package com.ithao.service.impl;

import com.ithao.dao.QuestionDao;
import com.ithao.dao.ReviewLogDao;
import com.ithao.dao.UserDao;
import com.ithao.pojo.ReviewLog;
import com.ithao.pojo.User;
import com.ithao.service.ReviewLogService;
import com.ithao.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author : ZhangHao
 * @version :1.0
 * @date :Created in 2020/3/30
 * @description : 题目审核服务
 */
@Service
@Slf4j
public class ReviewLogServiceImpl implements ReviewLogService {
    @Autowired
    private ReviewLogDao reviewLogDao;
    @Autowired
    private QuestionDao questionDao;
    @Autowired
    private UserDao userDao;

    @Override
    public void add(ReviewLog reviewLog) {
        if (reviewLog == null) {
            throw new RuntimeException("reviewLog为空");
        }
        //插入审核日志记录
        reviewLog.setCreateDate(DateUtils.parseDate2String(new Date()));
        reviewLogDao.add(reviewLog);

        //更新question状态
        Integer status = reviewLog.getStatus();
        if (1 == status) {//审核通过
            questionDao.updateReviewStatus(reviewLog.getQuestionId(), 1);//已审核
            //审核通过就自动上架
            questionDao.updateStatus(reviewLog.getQuestionId(), 1); //已发布
        }
        if (2 == status) {//审核不通过
            questionDao.updateReviewStatus(reviewLog.getQuestionId(), 1);//已审核
        }
    }
}
